<template>
  <div class="questionnaire_record">
    <navigate>问卷测评记录</navigate>
    <div>
      <div class="input_box dis_flex just_center">
        <searchInput
          class="search_input"
          type="text"
          v-model="name"
          placeholder="搜索测评量表名称"
          @input="handleSearch"
          @clearInput="clearInput"
        ></searchInput>
        <div class="dis_flex" @click="openPop">
          <div class="filtrate_txt">筛选</div>
          <img
            src="@/assets/images/evaluate/filtrate_icon.png"
            alt=""
            class="filtrate_img"
          />
        </div>
      </div>
    </div>
    <div class="record_box">
      <div v-for="(item, index) in recordList" :key="index">
        <div class="time_box dis_flex">
          <img
            src="@/assets/images/common/grey_clock.png"
            alt=""
            class="clock_img"
          />
          <div class="date_time">{{ item.time }}</div>
        </div>
        <div class="">
          <div
            class="white_box"
            @touchstart="startLongPress(v.id)"
            v-for="(v, index) in item.list"
            :key="index"
          >
            <div class="dis_flex">
              <img
                src="@/assets/images/common/bar.png"
                alt=""
                class="bar_img"
              />
              <div class="item_tit">{{ v.name }}</div>
              <img
                src="@/assets/images/evaluate/new_icon.png"
                alt=""
                class="new_img"
                v-if="false"
              />
            </div>
            <div class="info_box dis_flex just_space mar_top17">
              <div>发布人：{{ v.user_name }}</div>
              <div>包含量表：{{ v.paper_num }}个</div>
              <div>收费：￥0元/次</div>
            </div>
            <div class="dividing_line"></div>
            <div class="mar_top9 task_time_box" v-if="v.is_time == 1">
              <div class="left_txt">任务起止：</div>
              <div>
                <div class="task_time">
                  {{ convertTimestampToDateTime(v.start_time) }}
                </div>
                <div class="task_time end_time">
                  {{ convertTimestampToDateTime(v.end_time) }}
                </div>
              </div>
            </div>
            <div class="mar_top13 dis_flex">
              <div class="left_txt">查看权限：</div>
              <div class="dis_flex">
                <img
                  :src="
                    v.result_read_auth.includes('3') ? inactiveIcon : activeIcon
                  "
                  alt=""
                  class="img_icon"
                />
                <div class="left_txt">用户本人</div>
              </div>
              <div class="dis_flex">
                <img
                  :src="
                    v.result_read_auth.includes('4') ? inactiveIcon : activeIcon
                  "
                  alt=""
                  class="img_icon"
                />
                <div class="left_txt">用户家长</div>
              </div>
            </div>
            <div class="mar_top13 dis_flex">
              <div class="left_txt">报告生成：</div>
              <div class="left_txt">
                {{ convertTimestampToDateTime(v.time) }}
              </div>
            </div>

            <div class="check_btn" @click="checkReport(v)">查看报告</div>
          </div>
        </div>
      </div>
      <div class="no_data_txt">-- 无更多测评任务了 —-</div>
    </div>
    <filterPop
      :isShowPop="isShowFilter"
      @closeFilterPop="closeFilterPop"
      :type="6"
    />
  </div>
</template>

<script>
import { queryQnEvRecord } from "@/api/evaluation/questionnaire";
import { convertTimestampToDateTime } from "@/utils/time";
import searchInput from "@/components/searchInput/index.vue";
import filterPop from "./components/filterPop.vue";
import recordOperation from "./components/recordOperation.vue";

export default {
  data() {
    return {
      activeIcon: require("@/assets/images/common/radio1.png"),
      inactiveIcon: require("@/assets/images/common/radio11.png"),
      name: "",
      isShowFilter: false, // 筛选弹框
      filterInfo: {},
      isShowOperationPop: false, // 操作弹框
      pageSize: 10, // 分页大小
      page: 1, // 当前页码
      total: 0, // 总条数
      recordList: [], // 记录列表
    };
  },
  components: {
    searchInput,
    filterPop,
    recordOperation,
  },
  created() {
    this.getRecordList();
  },
  methods: {
    convertTimestampToDateTime,
    startLongPress() {},
    async getRecordList() {
      let par = {
        pageSize: this.pageSize,
        page: this.page,
        name: this.name,
        is_finish: this.filterInfo.is_finish,
        start_time: this.filterInfo.start_time,
        end_time: this.filterInfo.end_time,
      };
      let res = await queryQnEvRecord(par);
      if (res.code === 200) {
        // this.recordList = res.data.data;
        this.recordList = Object.keys(res.data).map((yearMonth) => {
          return {
            time: yearMonth,
            list: res.data[yearMonth].map((item) => ({
              ...item,
              isUnfold: false,
              needUnfold: false,
            })),
          };
        });
      }
    },
    closeFilterPop(val) {
      this.isShowFilter = false;
      this.filterInfo = val;
      this.getRecordList();
    },
    handleSearch(value) {
      this.name = value;
      if (this.searchTimer) {
        clearTimeout(this.searchTimer);
      }
      this.searchTimer = setTimeout(() => {
        this.getRecordList();
      }, 500);
    },
    clearInput() {
      this.name = "";
      this.getRecordList();
    },
    openPop() {
      this.isShowFilter = true;
    },
    checkReport(v) {
      this.$router.push({ path: `/questionnaireExport?id=${v.id}` });
    },
  },
};
</script>

<style lang="less" scoped>
.dis_flex {
  display: flex;
  align-items: center;
}
.just_center {
  justify-content: center;
}
.just_space {
  justify-content: space-between;
}
.mar_top13 {
  margin-top: 13px;
}
.mar_top9 {
  margin-top: 9px;
}
.mar_top17 {
  margin-top: 17px;
}
.white_box {
  position: relative;
  background: #ffffff;
  border-radius: 6.67px;
  padding: 17.33px 13.33px 13.33px 13.33px;
  margin-bottom: 10px;
  &:last-child {
    margin-bottom: 0;
  }
}
.questionnaire_record {
  background-color: #f4f6fa;
}
.input_box {
  width: 100%;
  height: 50px;
  background: #ffffff;
}
.search_input {
  width: 270px;
  height: 36.67px;
  margin: 0 10px 0 0;
  background: #f4f6fa;
}
.filtrate_txt {
  color: #333333;
  font-size: 14px;
  font-size: 14px;
}
.filtrate_img {
  width: 13.33px;
  height: 13.33px;
  margin-left: 5.67px;
}
.record_box {
  padding: 0 10px;
}
.input_box {
  width: 100%;
  height: 50px;
  background: #ffffff;
}
.search_input {
  width: 270px;
  height: 36.67px;
  margin: 0 10px 0 0;
  background: #f4f6fa;
}
.filtrate_txt {
  color: #333333;
  font-size: 14px;
  font-size: 14px;
}
.filtrate_img {
  width: 13.33px;
  height: 13.33px;
  margin-left: 5.67px;
}
.time_box {
  margin: 17px 0;
}
.clock_img {
  width: 12px;
  height: 12px;
  margin-right: 7.33px;
}
.date_time {
  color: #999999;
  font-size: 12px;
  line-height: 12px;
}

.bar_img {
  width: 5.33px;
  height: 15.33px;
}
.item_tit {
  width: 100%;
  color: #333333;
  font-size: 16.67px;
  margin: 0 10px;
}
.new_img {
  width: 20px;
  height: 20px;
}
.left_txt {
  font-size: 12.67px;
  color: #666666;
  margin-right: 13.33px;
}
.info_box {
  color: #333333;
  font-size: 12px;
  line-height: 12px;
}
.fish_ststate {
  font-size: 12.67px;
  color: #14c76a;
}
.task_time_box {
  display: flex;
}
.task_time {
  border: 0.33px solid #aaaaaa;
  border-radius: 4.67px;
  padding: 5px 6px;
  color: #666666;
  font-size: 12.67px;
}
.end_time {
  margin-top: 6.67px;
}
.check_btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 83.33px;
  height: 33.33px;
  line-height: 33.33px;
  background: linear-gradient(0deg, #ffffff -20%, rgba(255, 255, 255, 0) 20%),
    #00aeff;
  border-radius: 5.33px;
  color: #ffffff;
  font-size: 14.67px;
  text-align: center;
}
.no_data_txt {
  font-size: 14px;
  margin: 32px auto;
  text-align: center;
}
.dividing_line {
  border-bottom: 0.33px solid #dddddd;
  margin: 10px 0;
}
.img_icon {
  width: 15.33px;
  height: 15.33px;
  margin-right: 5px;
}
</style>
